package ru.alperez.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class ResultSavePoint extends Result{
	public enum PointSaveConflictType {
		CONFLICT_NAME,
		CONFLICT_LOCATION,
	};
	
	private boolean savedWithConflict;
	private List<Map<String, Object>> conflicts;
	
	public ResultSavePoint(boolean result, boolean savedWithConflict, String errorString) {
		super(result, result ? Result.ErrorCode.ERROR_NO_ERROR : Result.ErrorCode.ERROR_CONFLICT, errorString);
		this.setSavedWithConflict(savedWithConflict);
		conflicts = new ArrayList<Map<String,Object>>();
	}
	
	public List<Map<String, Object>> getConflicts() {
		return conflicts;
	}
	
	public void claerConflicts() {
		conflicts.clear();
	}
	
	public int getConflictNum() {
		return conflicts.size();
	}
	
	public int addConflict(GpsPoint point, PointSaveConflictType conflict) {
		if (point != null && conflict != null) {
			Map<String, Object> item = new HashMap<String, Object>();
			item.put("confl_type", conflict);
			item.put("location", point);
			conflicts.add(item);
		}
		return conflicts.size();
	}

	public boolean isSavedWithConflict() {
		return savedWithConflict;
	}

	public void setSavedWithConflict(boolean savedWithConflict) {
		this.savedWithConflict = savedWithConflict;
	}
}
